package sort;

public class SelectSort {
    public static void main(String[] args) {
        long startTime = System.currentTimeMillis();
        int[] arr = new int[80000];
        initArr(arr);
        selectSort(arr);
        //System.out.print(Arrays.toString(arr));
        long endTime = System.currentTimeMillis();
        System.out.println("程序运行时间：" + (endTime - startTime) + "ms");
    }


    static void initArr(int[] arr) {

        for (int i = 0; i < arr.length; i++) {
            arr[i] = (int) (Math.random() * 800000);
        }
    }
    public static void selectSort(int[] arr) {
        int min;
        int minIndex;
        for(int i = 0; i < arr.length; i++) {
            min = arr[i];
            minIndex = i;
            for(int j = i + 1; j < arr.length; j++) {
                if(min > arr[j]) {
                    minIndex = j;
                    min = arr[j];
                }
            }
            if(minIndex != i) {
                arr[minIndex] = arr[i];
                arr[i] = min;
            }
        }
    }
}
